package com.yuedou.api.service.product.impl;

import com.yuedou.api.dao.product.OrderAppraiseImgMapper;
import com.yuedou.api.entity.product.OrderAppraiseImg;
import com.yuedou.api.service.base.impl.BaseServiceImpl;
import com.yuedou.api.service.product.OrderAppraiseImgService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderAppraiseImgServiceImpl extends BaseServiceImpl<OrderAppraiseImgMapper, OrderAppraiseImg> implements OrderAppraiseImgService {
    @Resource
    private OrderAppraiseImgMapper orderAppraiseImgMapper;
    @Value("${web.imgPrefix}")
    private String imgPrefix;//图片地址

    @Override
    public OrderAppraiseImg selectByPrimaryKey(Integer id) {
        OrderAppraiseImg img = orderAppraiseImgMapper.selectById(id);
        if(img!=null){
            String img_key = img.getImgUrl()!=null ? img.getImgUrl() : "";
            if(!img_key.equals("")){
                img.setImgUrl(imgPrefix + img_key);
            }
        }
        return img;
    }

    @Override
    public List<OrderAppraiseImg> getListByAppraiseId(int appraiseId) {
        List<OrderAppraiseImg> imgs = orderAppraiseImgMapper.selectListByColumn("appraise_id",appraiseId);
        if(imgs!=null && imgs.size() > 0){
            for(OrderAppraiseImg img : imgs){
                if(img!=null){
                    String img_key = img.getImgUrl()!=null ? img.getImgUrl() : "";
                    if(!img_key.equals("")){
                        img.setImgUrl(imgPrefix + img_key);
                    }
                }
            }
        }
        return imgs;
    }
}
